//
//  ArtInfoTableViewCell.m
//  Arts1
//
//  Created by apple on 15/10/7.
//  Copyright © 2015年 Arts1. All rights reserved.
//

#import "ArtInfoTableViewCell.h"
#import "AllHeader.h"

@implementation ArtInfoTableViewCell

//初始化方法
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self overridView];
    }
    return self;
}

//自定义控件
- (void)overridView
{
    //背景视图
    _myBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, SCREEN_WIDTH - 20, 220 *HEIGHT)];
    _myBackgroundView.backgroundColor = kCustomColor(255, 255, 255, 1.0);
    [UIView viewShadowColor:_myBackgroundView];
    _myBackgroundView.layer.cornerRadius = 5;
    [self addSubview:_myBackgroundView];
    //图片
    _imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, _myBackgroundView.width, 169 *HEIGHT)];
    _imgView.backgroundColor = [UIColor grayColor];
    [UIView viewRediusForLeftAndReightOfTop:_imgView withRedius:5];
    _imgView.contentMode = UIViewContentModeScaleAspectFill;
    [_myBackgroundView addSubview:_imgView];
    //删除的模糊视图
    self.backView = [[UIView alloc] init];
    self.backView.layer.cornerRadius = 5;
    [self.myBackgroundView addSubview:self.backView];
    //删除的按钮
    self.deleteView = [[UIImageView alloc] init];
    self.deleteView.image = [UIImage imageNamed:@"TrashIcon"];
    [self.backView addSubview:self.deleteView];
    
    //简介
    self.labelInfo = [[UILabel alloc] initWithFrame:CGRectMake(10, _imgView.bottom + 5, 200 * WIDTH, 18 * HEIGHT)];
    self.labelInfo.font = [UIFont systemFontOfSize:13];
    self.labelInfo.textColor = [UIColor grayColor];
    [_myBackgroundView addSubview:self.labelInfo];
    
    //被浏览次数图标
    self.imgViews = [[UIImageView alloc] initWithFrame:CGRectMake(10, _labelInfo.bottom + 5, 15, 12)];
    self.imgViews.image = [UIImage imageNamed:@"ViewNum"];
    [_myBackgroundView addSubview:self.imgViews];
    
    //被浏览次数
    self.labelViews = [[UILabel alloc] initWithFrame:CGRectMake(self.imgViews.right + 5, _labelInfo.bottom + 5, 30, 11)];
    self.labelViews.textAlignment = NSTextAlignmentLeft;
    self.labelViews.font = [UIFont systemFontOfSize:11];
    self.labelViews.textColor = kCustomColor(180, 180, 180, 1.0);
    [_myBackgroundView addSubview:self.labelViews];
    
    //评论次数图标
    self.imgComments = [[UIImageView alloc] initWithFrame:CGRectMake(self.labelViews.right + 5, _labelInfo.bottom + 5, 15, 12)];
    self.imgComments.image = [UIImage imageNamed:@"CommentNumIcon"];
    [_myBackgroundView addSubview:self.imgComments];
    
    //评论次数
    self.labelComments = [[UILabel alloc] initWithFrame:CGRectMake(self.imgComments.right + 5, _labelInfo.bottom + 5, 30, 11)];
    self.labelComments.textAlignment = NSTextAlignmentLeft;
    self.labelComments.font = [UIFont systemFontOfSize:11];
    self.labelComments.textColor = kCustomColor(180, 180, 180, 1.0);
    [_myBackgroundView addSubview:self.labelComments];
    
    
    //标签
    self.labelTags = [[UILabel alloc] initWithFrame:CGRectMake(_myBackgroundView.right - 175 *WIDTH, _labelInfo.bottom + 5, 155, 14)];
    self.labelTags.textColor = kCustomColor(180, 180, 180, 1.0);
    self.labelTags.textAlignment = NSTextAlignmentRight;
    self.labelTags.font = [UIFont systemFontOfSize:13];
    [_myBackgroundView addSubview:self.labelTags];
    
}

//给视图赋值
- (void)setModel:(MypictureModel *)model
{
    _model = model;
    [_imgView sd_setImageWithURL:[NSURL URLWithString:_model.img] placeholderImage:nil options:SDWebImageRetryFailed | SDWebImageLowPriority];
    self.labelInfo.text = _model.info;
    
    self.labelViews.text = _model.views;
    
    self.labelComments.text = _model.comments;
    //如果标签没有值
    if (_model.tags.length == 0)
    {
        self.labelTags.text = _model.tags;
    }
    else
    {
        self.labelTags.text = [NSString stringWithFormat:@"%@",_model.tags];
    }
}

//开始编辑
- (void)beginEditing
{
    CGFloat backgroundViewX = 0;
    CGFloat backgroundViewY = 0;
    CGFloat backgroundViewW = _myBackgroundView.width;
    CGFloat backgroundViewH = _myBackgroundView.width * (190.0 / 304.0);
    
    self.backView.frame = CGRectMake(backgroundViewX, backgroundViewY, backgroundViewW, backgroundViewH);
    self.backView.backgroundColor = kCustomColor(18, 18, 18, 0.5);
    
    self.deleteView.frame = CGRectMake(0, 0, 40, 50);
    self.deleteView.centerX = self.backView.width * 0.5;
    self.deleteView.centerY = self.backView.height * 0.5;
}
//结束编辑
- (void)endEditing
{
    self.backView.frame = CGRectZero;
    
    self.deleteView.frame = CGRectZero;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
